package com.work.mb;

import java.io.Serializable;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.logging.Logger;

import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;

import com.work.dto.UserDto;
import com.work.facade.UserFacade;
import com.work.model.User;

/**
 * The Class UserMB.
 *
 * @author "Mihai Roman"
 */
@ManagedBean(name = "userMB")
@SessionScoped
public class UserMB implements Serializable {

	/** The Constant serialVersionUID. */
	private static final long serialVersionUID = 6105509329924365159L;
	private final static Logger LOG = Logger.getLogger(UserMB.class.getName()); 
	
	/** The user facade. */
	@EJB
	private UserFacade userFacade;
	
	/** The first name. */
	private String firstName;
	
	/** The last name. */
	private String lastName;
	
	/** The email. */
	private String email;
	
	/** The password. */
	private String password;
	
	/** The role. */
	private int role;
	
	/** The ck. */
	private String ck;
	
	/** The created by. */
	private int createdBy;
	
	/** The updated by. */
	private int updatedBy;
	
	/** The creation date. */
	private Date creationDate;
	
	/** The updated date. */
	private Date updatedDate;

	/**
	 * Gets the first name.
	 *
	 * @return the firstName
	 */
	public String getFirstName() {
		return firstName;
	}

	/**
	 * Sets the first name.
	 *
	 * @param firstName the firstName to set
	 */
	public void setFirstName(String firstName) {
		this.firstName = firstName;
	}

	/**
	 * Gets the last name.
	 *
	 * @return the lastName
	 */
	public String getLastName() {
		return lastName;
	}

	/**
	 * Sets the last name.
	 *
	 * @param lastName the lastName to set
	 */
	public void setLastName(String lastName) {
		this.lastName = lastName;
	}

	/**
	 * Gets the email.
	 *
	 * @return the email
	 */
	public String getEmail() {
		return email;
	}

	/**
	 * Sets the email.
	 *
	 * @param email the email to set
	 */
	public void setEmail(String email) {
		this.email = email;
	}

	/**
	 * Gets the password.
	 *
	 * @return the password
	 */
	public String getPassword() {
		return password;
	}

	/**
	 * Sets the password.
	 *
	 * @param password the password to set
	 */
	public void setPassword(String password) {
		this.password = password;
	}

	/**
	 * Gets the role.
	 *
	 * @return the role
	 */
	public int getRole() {
		return role;
	}

	/**
	 * Sets the role.
	 *
	 * @param role the role to set
	 */
	public void setRole(int role) {
		this.role = role;
	}

	/**
	 * Gets the ck.
	 *
	 * @return the ck
	 */
	public String getCk() {
		return ck;
	}

	/**
	 * Sets the ck.
	 *
	 * @param ck the ck to set
	 */
	public void setCk(String ck) {
		this.ck = ck;
	}

	/**
	 * Gets the created by.
	 *
	 * @return the createdBy
	 */
	public int getCreatedBy() {
		return createdBy;
	}

	/**
	 * Sets the created by.
	 *
	 * @param createdBy the createdBy to set
	 */
	public void setCreatedBy(int createdBy) {
		this.createdBy = createdBy;
	}

	/**
	 * Gets the updated by.
	 *
	 * @return the updatedBy
	 */
	public int getUpdatedBy() {
		return updatedBy;
	}

	/**
	 * Sets the updated by.
	 *
	 * @param updatedBy the updatedBy to set
	 */
	public void setUpdatedBy(int updatedBy) {
		this.updatedBy = updatedBy;
	}

	/**
	 * Gets the creation date.
	 *
	 * @return the creationDate
	 */
	public Date getCreationDate() {
		return creationDate;
	}

	/**
	 * Sets the creation date.
	 *
	 * @param creationDate the creationDate to set
	 */
	public void setCreationDate(Date creationDate) {
		this.creationDate = creationDate;
	}

	/**
	 * Gets the updated date.
	 *
	 * @return the updatedDate
	 */
	public Date getUpdatedDate() {
		return updatedDate;
	}

	/**
	 * Sets the updated date.
	 *
	 * @param updatedDate the updatedDate to set
	 */
	public void setUpdatedDate(Date updatedDate) {
		this.updatedDate = updatedDate;
	}
	

	/**
	 * Save user.
	 *
	 * @return the string
	 */
	public String saveUser() {
		UserDto userDto = new UserDto();
		userDto.setDtoCK(userDto.getDtoCK());
		userDto.setDtoCreatedBy(role);
		userDto.setDtoUpdatedBy(role);
		userDto.setDtoCreationDate(Calendar.getInstance().getTime());
		userDto.setDtoUpdatedDate(Calendar.getInstance().getTime());
		userDto.setDtoFirstName(firstName);
		userDto.setDtoLastName(lastName);
		userDto.setDtoEmail(email);
		userDto.setDtoRole(role);
		userFacade.saveUser(userDto);
		return "listUsers";
	}
	
	public List<User> getUserList() {
		return userFacade.findAll();
	}

}
